#include<iostream>
#include<cstdio>|
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int n, m;
int w[N];
struct node
{
	int l, r;
	int ma;
}tree[N * 4];
void pushup(int u)
{
	tree[u].ma = max(tree[u << 1].ma, tree[u << 1 | 1].ma);
}
void build(int u, int l, int r)
{
	if (l == r) {
		tree[u] = { l,r,w[l] };
	}
	else {
		tree[u] = { l,r };
		int mid = (l + r) / 2;
		build(u << 1, l, mid);
		build(u << 1 | 1, mid + 1, r);
		pushup(u);
	}
}
void modify(int u, int x, int v)
{
	if (tree[u].l == x && tree[u].r == x) {
		tree[u].ma = v;
	}
	else {
		int mid = (tree[u].l + tree[u].r) / 2;
		if (x <= mid)modify(u << 1, x, v);
		else modify(u << 1 | 1, x, v);
		pushup(u);
	}
}
int query(int u, int l, int r)
{
	if (tree[u].l >= l && tree[u].r <= r) {
		return tree[u].ma;
	}
	else {
		int ans = 0;
		int mid = (tree[u].l + tree[u].r) / 2;
		if (l <= mid)ans = query(u << 1, l, r);
		if (r > mid)ans = max(ans, query(u << 1 | 1, l, r));
		return ans;
	}
}
int main()
{
	while (cin >> n >> m) {
		memset(tree, 0, sizeof(tree));
		memset(w, 0, sizeof(w));
		for (int i = 1; i <= n; i++) {
			scanf("%d", &w[i]);
		}
		build(1, 1, n);
		while (m--) {
			char op[2];
			scanf("%s", op);
			int l, r;
			scanf("%d%d", &l, &r);
			if (op[0] == 'Q') {
				printf("%d\n", query(1, l, r));
			}
			else {
				modify(1, l, r);
			}
		}
	}
	return 0;
}